package com.example.roledepartment.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author cc
 * @classname Knife4jConfig
 * @description TODO
 * @date 2022/8/12 13:53
 */
@Configuration
public class Knife4jConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)      // 选择swagger2版本
                .useDefaultResponseMessages(true)
                .apiInfo(apiInfo())         //定义api文档汇总信息
                .groupName("v1.0").pathMapping("/") // 分组名称
                .select()
                .apis(RequestHandlerSelectors
                        .basePackage("com.example.roledepartment.controller"))  // 这里指定Controller扫描包路径
                .paths(PathSelectors.any())     // 指定所有路径
                .build();
    }

    /**
     * 构建文档api信息
     *
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口文档")     // 文档标题
                .contact(new Contact("cc", "url", "mail"))   //联系人信息
                .description("接口文档")      //描述
                .version("v1.0")     //文档版本号
                .termsOfServiceUrl("http://127.0.0.1:9001")     //网站地址
                .build();
    }
}
